package org.netty.encoder;

import java.util.List;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;

/**
 * 绝对值编码
 * Description:
 * @author zpp
 * @date   2018年5月3日
 */
public class AbsIntegerEncoder extends MessageToMessageEncoder<ByteBuf> {  //1
	
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> out) throws Exception {
        while (in.readableBytes() >= 4) { //2
            int value = Math.abs(in.readInt());//3
            System.out.println(value);
            out.add(value);  //4
        }
    }
}